package com.example.common;

import androidx.annotation.NonNull;


import com.blankj.utilcode.util.LogUtils;

import java.io.IOException;
import java.util.HashSet;

import okhttp3.Interceptor;
import okhttp3.Response;

public class ReceivedCookiesInterceptor implements Interceptor {

    public static String cookie = "cookie";

    @NonNull
    @Override
    public Response intercept(Chain chain) throws IOException {
        Response originalResponse = chain.proceed(chain.request());
        assert originalResponse.body() != null;
        if (!originalResponse.headers("Set-Cookie").isEmpty()) {
            HashSet<String> hashSet = new HashSet<>();
            for (String header : originalResponse.headers("Set-Cookie")) {
                hashSet.add(header);
            }
            MMKVUtils.Companion.putString(ReceivedCookiesInterceptor.cookie,hashSet);
        }
        return originalResponse;
    }
}
